﻿using Lockstep.Collision2D;
using Lockstep.Math;
using System;
using UnityEngine;

namespace Lockstep.Game
{
    /// <summary>
    /// 基础地图物体类
    /// </summary>
    [NoBackup]
    [Serializable]
    public partial class MapItemEntity : BaseEntity
    {
        [NoBackup, HideInInspector]
        public WallCellConfig config;

        public void InitData(WallCellConfig _config) {
            config = _config;
            ConfigId = (int)_config.type;
            colliderData = _config.colliderData;
        }

        protected override void BindRef()
        {
            base.BindRef();
        }

        public override void DoAwake()
        {
            base.DoAwake();
        }

        public override void DoStart()
        {
            base.DoStart();
        }

        public virtual void TakeDamage(BaseEntity atker, int amount, LVector3 hitPoint)
        {
            DebugService.Trace($"{atker.EntityId} attack {EntityId}  damage:{amount} hitPos:{hitPoint}");
            EntityView?.OnTakeDamage(amount, hitPoint);
            OnTakeDamage(amount, hitPoint);
            if (config.type == SceneObjType.Home || config.type == SceneObjType.Brick) {
                DoDead();
            }
        }

        protected virtual void OnTakeDamage(int amount, LVector3 hitPoint) { }

        public override void DoDestroy()
        {
            base.DoDestroy();
            if (EntityView != null) { 
                EntityView?.OnDead();
                EntityView = null;  
            }
        }
    }
}
